@include('admin.layout.bone_header')

<div class="layui-btn-container">


</div>


<table class="layui-hide" id="think-table" lay-filter="think-table"></table>

<script type="text/html" id="barDemo">

    <a class="layui-btn layui-btn-xs" lay-event="recharge">充值</a>
    <a class="layui-btn layui-btn-xs" lay-event="set_shop">商家</a>


</script>

<script>

    layui.use('table', function () {
        let table = layui.table;
        UI.getPageTable(table, "{{route('admin.users.users')}}", [
            {field: 'user_id', title: 'ID', width: 80, sort: true, fixed: 'left'}
            , {field: 'nickname', title: '用户昵称'}
            , {field: 'phone', title: '手机号'}
            , {field: 'money', title: '余额'}
            , {field: 'consumer', title: '消费券'}
            , {field: 'spread_id', title: '推荐人'}
            , {field: 'pv_nums_tuan', title: '团队PV'}
            , {field: 'pv_nums_ziji', title: '个人PV'}
            , {field: 'money', title: '等级',templet:function (d){
                let arr = ['免费会员','银卡会员','金卡会员','钻卡会员','福卡会员','尊卡会员'];
                return arr[d['vip_level']]
                }}
            , {field: 'money', title: '董事等级',templet:function (d){
                    let arr = ['暂未开通','初级董事','中级董事','高级董事'];
                    return arr[d['vip_dong_level']]
                }}
            , {field: 'money', title: '商家等级',templet:function (d){
                    let arr = ['暂未开通','乡镇店','县级店','市级店','省级店'];
                    return arr[d['shop_level']]+d['shop_nums']
                }}
            , {field: 'money', title: '商家区域',templet:function (d){
                    return d['extra_city_str']
                }}
            ,{fixed: 'right',title:'操作', align:'center', toolbar: '#barDemo'}
        ]);

        table.on('tool(think-table)', function (obj) {
            let data = obj.data;
            if(obj.event === 'recharge') {
                layer.prompt({formType:0,title:"充值",value:10000},
                    function(value, index){
                        if(value < 1){
                            Utils.errorToast('最少充值1');
                            return;
                        }
                        HttpUtils.post('{{route('admin.users.recharge')}}',{
                            money:value,
                            user_id:data['user_id']
                        },function (res){
                            layer.close(index)
                            layui.table.reload("think-table");
                        });
                    });
            }else if(obj.event === 'set_shop'){
                UI.openLayer("{{route('admin.users.set_shop')}}?user_id="+data['user_id'],1080);
            }
        });
        let $ = layui.$, active = {

        };
        $('.layui-btn-container .layui-btn').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $('.search .layui-btn').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    })


</script>


@include('admin.layout.bone_footer')
